package demo13.Practice01;

public class DFactorySimulator {
	public static void main(String[] args) {
		
		DFactorySimulator dfs = new DFactorySimulator();
		//工厂模式
		AbstractDuckFactory duckFactory = new CountingDuckFactory();
		dfs.simulate(duckFactory);
		
/*		鸭子工厂开始统计鸭子叫
		绿头鸭呱呱叫
		橡皮鸭子吱吱叫
		红头鸭子呱呱叫
		大鹅叫
		鸭子叫了3次*/
	}

	
	public void simulate(AbstractDuckFactory duckFactory){//传入一个鸭子工厂用于创建鸭子
		 Quackable mallarDuck = duckFactory.createMallardDuck();
		 Quackable redhradDuck = duckFactory.createRedheadDuck();
		 Quackable rubberDuck = duckFactory.createRubberDuck();
		 Quackable gooseDuck = new GooseAdapter(new Goose());//大鹅不去装饰
		 System.out.println("鸭子工厂开始统计鸭子叫");
		 simulate(mallarDuck);
		 simulate(rubberDuck);
		 simulate(redhradDuck);
		 simulate(gooseDuck);
		 System.out.println("鸭子叫了"+QuackCounter.getQuacks()+"次");
		 
	 }
	 
	 public void simulate(Quackable duck){
		 duck.query();
		 	 
	 }
}
